package com.yxp.offer;


import java.util.Stack;

/**
 * Your CQueue object will be instantiated and called as such:
 * CQueue obj = new CQueue();
 * obj.appendTail(value);
 * <p>
 * int param_2 = obj.deleteHead();
 * CQueue
 * deleteHead
 * appendTail
 * 剑指 Offer 09. 用两个栈实现队列
 */

public class Problem09 {

    public Stack<Integer> putStack;
    public Stack<Integer> removeStack;

    public Problem09() {
        putStack = new Stack<>();
        removeStack = new Stack<>();
    }

    public void appendTail(int value) {
        putStack.push(value);
    }

    public int deleteHead() {
        if (removeStack.isEmpty()) {
            if (putStack.isEmpty()) {
                return -1;
            }
            int size = putStack.size();
            for (int i = 0; i < size; i++) {
                removeStack.push(putStack.pop());
            }
        }
        return removeStack.pop();
    }

    public static void main(String[] args) {
        Problem09 problem09 = new Problem09();
        problem09.putStack.push(1);
        problem09.putStack.push(2);
        problem09.putStack.push(3);
        problem09.putStack.push(4);
        for (int i = 0; i < problem09.putStack.size(); i++) {
            problem09.removeStack.push(problem09.putStack.pop());
        }
    }
}
